﻿using Cms.Domain;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Cms.Tests.Unit.Domain
{
    /// <summary>
    /// Summary description for PageCategoryTests
    /// </summary>
    [TestClass]
    public class PageCategoryTests
    {

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestContainsPage()
        {
            Page p1 = new Page { ID = 1 };
            Page p2 = new Page { ID = 2 };
            Category pc = new Category() { ID = 1, Name = "test"};
            pc.Pages.Add(p1);
            p1.Categories.Add(pc);
            Assert.IsTrue(pc.ContainsPage(p1));
            Assert.IsFalse(pc.ContainsPage(p2));
        }


        [TestMethod]
        public void TestContainsFolder()
        {
            Folder f1 = new Folder { ID = 1 };
            Folder f2 = new Folder { ID = 2 };
            Category pc = new Category() { Name = "xxx" };
            pc.Folders.Add(f1);
            f1.Categories.Add(pc);
            Assert.IsTrue(pc.ContainsFolder(f1));
            Assert.IsFalse(pc.ContainsFolder(f2));
        }


        [TestMethod]
        public void TestContainsPageViaFolder()
        {
            Page p1 = new Page { ID = 1 };
            Folder f1 = new Folder { ID = 1 };
            Category pc = new Category() { ID = 1, Name = "Cars" };
            pc.Folders.Add(f1);
            f1.Categories.Add(pc);
            p1.Folder = f1;
            f1.Pages.Add(p1);
            Assert.IsTrue(pc.ContainsPage(p1));
        }

    }

}
